{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# The Double Pendulum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#'double-pendulum/tex"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(require '[clojupyter.misc.helper :as helper])\n",
    "(run! helper/add-dependencies '[[org.clojure/data.json \"0.2.6\"]\n",
    "                                [net.littleredcomputer/sicmutils \"0.12.0-SNAPSHOT\"]\n",
    "                                [thi.ng/geom \"0.0.908\"]])\n",
    "(ns double-pendulum\n",
    "    (:refer-clojure :exclude [partial zero? + - * / ref])\n",
    "    (:require [sicmutils.env :refer :all]\n",
    "              [clojupyter.misc.display :as display]\n",
    "              [thi.ng.geom.viz.core :as viz]\n",
    "              [thi.ng.geom.svg.core :as svg]))\n",
    "(defn tex [x] (-> x tex$$ display/latex))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#'double-pendulum/V"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(defn V\n",
    "  [m_1 m_2 l_1 l_2 g]\n",
    "  (fn [[_ [theta phi] _]]\n",
    "    (let [y_1 (- (* l_1 (cos theta)))\n",
    "          y_2 (- y_1 (* l_2 (cos phi)))]\n",
    "      (+ (* m_1 g y_1)\n",
    "         (* m_2 g y_2)))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#'double-pendulum/T"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(defn T\n",
    "  [m_1 m_2 l_1 l_2 _]\n",
    "  (fn [[_ [theta phi] [thetadot phidot]]]\n",
    "    (let [v1sq (* (square l_1) (square thetadot))\n",
    "          v2sq (* (square l_2) (square phidot))]\n",
    "      (+ (* 1/2 m_1 v1sq)\n",
    "         (* 1/2 m_2 (+ v1sq\n",
    "                      v2sq\n",
    "                      (* 2 l_1 l_2 thetadot phidot (cos (- theta phi)))))))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$l_1\\,l_2\\,m_2\\,\\dot {\\phi}\\,\\dot {\\theta}\\,\\cos\\left(- \\phi + \\theta\\right) + \\frac{1}{2}\\,{l_1}^{2}\\,m_1\\,{\\dot {\\theta}}^{2} + \\frac{1}{2}\\,{l_1}^{2}\\,m_2\\,{\\dot {\\theta}}^{2} + \\frac{1}{2}\\,{l_2}^{2}\\,m_2\\,{\\dot {\\phi}}^{2} + g\\,l_1\\,m_1\\,\\cos\\left(\\theta\\right) + g\\,l_1\\,m_2\\,\\cos\\left(\\theta\\right) + g\\,l_2\\,m_2\\,\\cos\\left(\\phi\\right)$$"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(def L (- T V))\n",
    "(tex ((L 'm_1 'm_2 'l_1 'l_2 'g) \n",
    "       (up 't \n",
    "           (up 'theta 'phi) \n",
    "           (up 'thetadot 'phidot))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#'double-pendulum/state-derivative"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(defn state-derivative [m_1 m_2 l_1 l_2 g]\n",
    "    (Lagrangian->state-derivative\n",
    "        (L m_1 m_2 l_1 l_2 g)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#'double-pendulum/equations-of-motion"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(def equations-of-motion\n",
    "    ((state-derivative 'm_1 'm_2 'l_1 'l_2 'g)\n",
    "               (up 't\n",
    "                   (up 'theta 'phi)\n",
    "                   (up 'thetadot 'phidot))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\begin{pmatrix}\\frac{- l_1\\,m_2\\,{\\dot {\\theta}}^{2}\\,\\cos\\left(- \\phi + \\theta\\right)\\,\\sin\\left(- \\phi + \\theta\\right) - l_2\\,m_2\\,{\\dot {\\phi}}^{2}\\,\\sin\\left(- \\phi + \\theta\\right) + g\\,m_2\\,\\cos\\left(- \\phi + \\theta\\right)\\,\\sin\\left(\\phi\\right) - g\\,m_1\\,\\sin\\left(\\theta\\right) - g\\,m_2\\,\\sin\\left(\\theta\\right)}{l_1\\,m_2\\,{\\sin}^{2}\\left(- \\phi + \\theta\\right) + l_1\\,m_1}\\\\\\frac{l_2\\,m_2\\,{\\dot {\\phi}}^{2}\\,\\cos\\left(- \\phi + \\theta\\right)\\,\\sin\\left(- \\phi + \\theta\\right) + l_1\\,m_1\\,{\\dot {\\theta}}^{2}\\,\\sin\\left(- \\phi + \\theta\\right) + l_1\\,m_2\\,{\\dot {\\theta}}^{2}\\,\\sin\\left(- \\phi + \\theta\\right) + g\\,m_1\\,\\cos\\left(- \\phi + \\theta\\right)\\,\\sin\\left(\\theta\\right) + g\\,m_2\\,\\cos\\left(- \\phi + \\theta\\right)\\,\\sin\\left(\\theta\\right) - g\\,m_1\\,\\sin\\left(\\phi\\right) - g\\,m_2\\,\\sin\\left(\\phi\\right)}{l_2\\,m_2\\,{\\sin}^{2}\\left(- \\phi + \\theta\\right) + l_2\\,m_1}\\end{pmatrix}$$"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(tex (nth equations-of-motion 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\begin{pmatrix}9.999999999999954\\\\\\begin{pmatrix}0.11375091645060717\\\\-2.223620451765166\\end{pmatrix}\\\\\\begin{pmatrix}-1.7171709187549014\\\\0.5300899328860362\\end{pmatrix}\\end{pmatrix}$$"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(def out (atom []))\n",
    "(defn observe [t [_ [theta phi]]] (swap! out conj [t theta phi]))\n",
    "(tex ((evolve state-derivative 1 1 1 1 9.8)\n",
    "      (up 0 (up (/ pi 2) 0) (up 0 0))\n",
    "      observe\n",
    "      1/60\n",
    "      10\n",
    "      1e-6\n",
    "      :compile true))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "#'double-pendulum/spec"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(def spec\n",
    "  {:x-axis (viz/linear-axis\n",
    "            {:domain [(first (first @out)) (first (last @out))]\n",
    "             :range  [50 (- 985 10)]\n",
    "             :major 1\n",
    "             :pos    550})\n",
    "   :y-axis (viz/linear-axis\n",
    "            {:domain      [(- Math/PI) Math/PI]\n",
    "             :range       [550 20]\n",
    "             :major       1\n",
    "             :minor       0.2\n",
    "             :pos         50\n",
    "             :label-dist  15\n",
    "             :label-style {:text-anchor \"end\"}})\n",
    "   :grid   {:attribs {:stroke \"#caa\"}\n",
    "            :minor-x true\n",
    "            :minor-y false}\n",
    "   :data   [{:values  (map #(vector (nth % 0) (nth % 1)) @out)\n",
    "             :attribs {:stroke \"#0af\" :stroke-width \"2pt\"}\n",
    "             :layout  viz/svg-line-plot}\n",
    "            {:values  (map #(vector (nth % 0) (nth % 2)) @out)\n",
    "             :attribs {:stroke \"#f60\" :stroke-width \"2pt\"}\n",
    "             :layout  viz/svg-line-plot}]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<?xml version=\"1.0\"?>\n",
       "<svg height=\"600\" version=\"1.1\" width=\"985\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://www.w3.org/2000/svg\"><g><g stroke-dasharray=\"1 1\" stroke=\"#caa\"><line x1=\"50.00\" x2=\"50.00\" y1=\"550.00\" y2=\"20.00\" /><line x1=\"142.50\" x2=\"142.50\" y1=\"550.00\" y2=\"20.00\" /><line x1=\"235.00\" x2=\"235.00\" y1=\"550.00\" y2=\"20.00\" /><line x1=\"327.50\" x2=\"327.50\" y1=\"550.00\" y2=\"20.00\" /><line x1=\"420.00\" x2=\"420.00\" y1=\"550.00\" y2=\"20.00\" /><line x1=\"512.50\" x2=\"512.50\" y1=\"550.00\" y2=\"20.00\" /><line x1=\"605.00\" x2=\"605.00\" y1=\"550.00\" y2=\"20.00\" /><line x1=\"697.50\" x2=\"697.50\" y1=\"550.00\" y2=\"20.00\" /><line x1=\"790.00\" x2=\"790.00\" y1=\"550.00\" y2=\"20.00\" /><line x1=\"882.50\" x2=\"882.50\" y1=\"550.00\" y2=\"20.00\" /><line x1=\"975.00\" x2=\"975.00\" y1=\"550.00\" y2=\"20.00\" /><line x1=\"50.00\" x2=\"975.00\" y1=\"538.06\" y2=\"538.06\" /><line x1=\"50.00\" x2=\"975.00\" y1=\"453.70\" y2=\"453.70\" /><line x1=\"50.00\" x2=\"975.00\" y1=\"369.35\" y2=\"369.35\" /><line x1=\"50.00\" x2=\"975.00\" y1=\"285.00\" y2=\"285.00\" /><line x1=\"50.00\" x2=\"975.00\" y1=\"200.65\" y2=\"200.65\" /><line x1=\"50.00\" x2=\"975.00\" y1=\"116.30\" y2=\"116.30\" /><line x1=\"50.00\" x2=\"975.00\" y1=\"31.94\" y2=\"31.94\" /></g><polyline fill=\"none\" points=\"50.00,152.50 51.54,152.61 53.08,152.96 54.63,153.53 56.17,154.34 57.71,155.37 59.25,156.63 60.79,158.13 62.33,159.85 63.88,161.81 65.42,164.00 66.96,166.42 68.50,169.08 70.04,171.99 71.58,175.14 73.13,178.54 74.67,182.21 76.21,186.16 77.75,190.39 79.29,194.94 80.83,199.83 82.38,205.09 83.92,210.75 85.46,216.86 87.00,223.43 88.54,230.47 90.08,237.91 91.63,245.60 93.17,253.32 94.71,260.89 96.25,268.17 97.79,275.14 99.33,281.80 100.88,288.17 102.42,294.30 103.96,300.19 105.50,305.89 107.04,311.39 108.58,316.71 110.13,321.85 111.67,326.80 113.21,331.56 114.75,336.11 116.29,340.43 117.83,344.51 119.38,348.32 120.92,351.84 122.46,355.06 124.00,357.95 125.54,360.49 127.08,362.66 128.63,364.44 130.17,365.81 131.71,366.75 133.25,367.25 134.79,367.28 136.33,366.82 137.88,365.85 139.42,364.34 140.96,362.27 142.50,359.63 144.04,356.43 145.58,352.76 147.13,348.76 148.67,344.65 150.21,340.64 151.75,336.87 153.29,333.40 154.83,330.22 156.38,327.31 157.92,324.64 159.46,322.18 161.00,319.88 162.54,317.73 164.08,315.70 165.63,313.75 167.17,311.87 168.71,310.05 170.25,308.25 171.79,306.48 173.33,304.70 174.88,302.91 176.42,301.09 177.96,299.24 179.50,297.34 181.04,295.39 182.58,293.37 184.13,291.27 185.67,289.10 187.21,286.85 188.75,284.51 190.29,282.09 191.83,279.57 193.38,276.97 194.92,274.29 196.46,271.54 198.00,268.71 199.54,265.82 201.08,262.87 202.63,259.88 204.17,256.87 205.71,253.84 207.25,250.80 208.79,247.78 210.33,244.79 211.88,241.84 213.42,238.96 214.96,236.16 216.50,233.45 218.04,230.87 219.58,228.42 221.13,226.12 222.67,223.99 224.21,222.05 225.75,220.31 227.29,218.80 228.83,217.52 230.38,216.49 231.92,215.72 233.46,215.22 235.00,215.01 236.54,215.10 238.08,215.49 239.63,216.19 241.17,217.22 242.71,218.59 244.25,220.31 245.79,222.39 247.33,224.87 248.88,227.78 250.42,231.15 251.96,235.03 253.50,239.50 255.04,244.63 256.58,250.52 258.13,257.21 259.67,264.57 261.21,272.19 262.75,279.54 264.29,286.26 265.83,292.26 267.38,297.59 268.92,302.35 270.46,306.63 272.00,310.49 273.54,313.99 275.08,317.17 276.63,320.08 278.17,322.74 279.71,325.17 281.25,327.39 282.79,329.42 284.33,331.26 285.88,332.94 287.42,334.46 288.96,335.82 290.50,337.04 292.04,338.13 293.58,339.08 295.13,339.90 296.67,340.59 298.21,341.17 299.75,341.63 301.29,341.97 302.83,342.20 304.38,342.32 305.92,342.33 307.46,342.23 309.00,342.02 310.54,341.72 312.08,341.31 313.63,340.79 315.17,340.19 316.71,339.48 318.25,338.68 319.79,337.79 321.33,336.81 322.88,335.75 324.42,334.60 325.96,333.39 327.50,332.10 329.04,330.74 330.58,329.33 332.13,327.86 333.67,326.35 335.21,324.79 336.75,323.21 338.29,321.59 339.83,319.96 341.38,318.31 342.92,316.65 344.46,314.99 346.00,313.33 347.54,311.68 349.08,310.03 350.63,308.39 352.17,306.77 353.71,305.14 355.25,303.53 356.79,301.91 358.33,300.28 359.88,298.65 361.42,296.99 362.96,295.31 364.50,293.58 366.04,291.80 367.58,289.96 369.13,288.03 370.67,286.00 372.21,283.86 373.75,281.57 375.29,279.13 376.83,276.49 378.38,273.63 379.92,270.50 381.46,267.07 383.00,263.27 384.54,259.04 386.08,254.33 387.63,249.11 389.17,243.44 390.71,237.54 392.25,231.80 393.79,226.55 395.33,221.97 396.88,218.11 398.42,214.94 399.96,212.39 401.50,210.41 403.04,208.98 404.58,208.05 406.13,207.60 407.67,207.60 409.21,208.04 410.75,208.89 412.29,210.15 413.83,211.79 415.38,213.79 416.92,216.14 418.46,218.80 420.00,221.76 421.54,224.99 423.08,228.45 424.63,232.14 426.17,236.00 427.71,240.02 429.25,244.17 430.79,248.43 432.33,252.77 433.88,257.17 435.42,261.62 436.96,266.10 438.50,270.60 440.04,275.12 441.58,279.65 443.13,284.21 444.67,288.79 446.21,293.41 447.75,298.09 449.29,302.84 450.83,307.68 452.38,312.66 453.92,317.80 455.46,323.15 457.00,328.73 458.54,334.58 460.08,340.70 461.63,347.02 463.17,353.37 464.71,359.55 466.25,365.34 467.79,370.64 469.33,375.41 470.88,379.67 472.42,383.43 473.96,386.75 475.50,389.65 477.04,392.15 478.58,394.28 480.13,396.06 481.67,397.49 483.21,398.58 484.75,399.35 486.29,399.79 487.83,399.91 489.38,399.72 490.92,399.21 492.46,398.40 494.00,397.28 495.54,395.86 497.08,394.15 498.63,392.15 500.17,389.88 501.71,387.33 503.25,384.53 504.79,381.48 506.33,378.20 507.88,374.70 509.42,370.99 510.96,367.09 512.50,363.01 514.04,358.75 515.58,354.33 517.13,349.74 518.67,345.01 520.21,340.11 521.75,335.04 523.29,329.80 524.83,324.36 526.38,318.69 527.92,312.77 529.46,306.53 531.00,299.93 532.54,292.89 534.08,285.37 535.63,277.33 537.17,268.89 538.71,260.31 540.25,251.97 541.79,244.12 543.33,236.86 544.88,230.18 546.42,224.00 547.96,218.28 549.50,212.93 551.04,207.93 552.58,203.23 554.13,198.80 555.67,194.63 557.21,190.69 558.75,186.98 560.29,183.49 561.83,180.21 563.38,177.14 564.92,174.28 566.46,171.63 568.00,169.18 569.54,166.95 571.08,164.93 572.63,163.13 574.17,161.54 575.71,160.18 577.25,159.03 578.79,158.11 580.33,157.41 581.88,156.94 583.42,156.70 584.96,156.69 586.50,156.90 588.04,157.34 589.58,158.01 591.13,158.90 592.67,160.02 594.21,161.36 595.75,162.92 597.29,164.71 598.83,166.71 600.38,168.93 601.92,171.38 603.46,174.04 605.00,176.92 606.54,180.02 608.08,183.35 609.63,186.92 611.17,190.73 612.71,194.79 614.25,199.14 615.79,203.78 617.33,208.75 618.88,214.09 620.42,219.86 621.96,226.10 623.50,232.88 625.04,240.24 626.58,248.16 628.13,256.47 629.67,264.85 631.21,272.98 632.75,280.68 634.29,287.92 635.83,294.71 637.38,301.14 638.92,307.24 640.46,313.09 642.00,318.70 643.54,324.12 645.08,329.37 646.63,334.46 648.17,339.40 649.71,344.19 651.25,348.83 652.79,353.32 654.33,357.64 655.88,361.78 657.42,365.74 658.96,369.49 660.50,373.01 662.04,376.30 663.58,379.34 665.13,382.11 666.67,384.60 668.21,386.79 669.75,388.67 671.29,390.24 672.83,391.49 674.38,392.40 675.92,392.98 677.46,393.21 679.00,393.09 680.54,392.61 682.08,391.77 683.63,390.55 685.17,388.95 686.71,386.94 688.25,384.51 689.79,381.63 691.33,378.28 692.88,374.41 694.42,369.99 695.96,365.03 697.50,359.57 699.04,353.74 700.58,347.76 702.13,341.86 703.67,336.18 705.21,330.78 706.75,325.65 708.29,320.77 709.83,316.09 711.38,311.58 712.92,307.20 714.46,302.91 716.00,298.69 717.54,294.52 719.08,290.38 720.63,286.25 722.17,282.12 723.71,277.98 725.25,273.83 726.79,269.66 728.33,265.48 729.88,261.29 731.42,257.10 732.96,252.92 734.50,248.77 736.04,244.66 737.58,240.61 739.13,236.66 740.67,232.81 742.21,229.11 743.75,225.57 745.29,222.23 746.83,219.11 748.38,216.23 749.92,213.63 751.46,211.32 753.00,209.33 754.54,207.67 756.08,206.36 757.63,205.43 759.17,204.87 760.71,204.72 762.25,204.97 763.79,205.65 765.33,206.77 766.88,208.36 768.42,210.45 769.96,213.07 771.50,216.27 773.04,220.10 774.58,224.63 776.13,229.90 777.67,235.85 779.21,242.27 780.75,248.76 782.29,254.93 783.83,260.58 785.38,265.69 786.92,270.30 788.46,274.48 790.00,278.30 791.54,281.81 793.08,285.06 794.63,288.10 796.17,290.94 797.71,293.64 799.25,296.19 800.79,298.64 802.33,300.99 803.88,303.25 805.42,305.45 806.96,307.60 808.50,309.70 810.04,311.76 811.58,313.80 813.13,315.81 814.67,317.79 816.21,319.76 817.75,321.71 819.29,323.64 820.83,325.55 822.38,327.44 823.92,329.30 825.46,331.12 827.00,332.90 828.54,334.64 830.08,336.32 831.63,337.94 833.17,339.50 834.71,340.98 836.25,342.39 837.79,343.71 839.33,344.93 840.88,346.07 842.42,347.10 843.96,348.02 845.50,348.84 847.04,349.54 848.58,350.13 850.13,350.60 851.67,350.96 853.21,351.18 854.75,351.29 856.29,351.27 857.83,351.12 859.38,350.85 860.92,350.45 862.46,349.91 864.00,349.25 865.54,348.45 867.08,347.51 868.63,346.43 870.17,345.22 871.71,343.86 873.25,342.35 874.79,340.68 876.33,338.86 877.88,336.86 879.42,334.69 880.96,332.33 882.50,329.76 884.04,326.98 885.58,323.95 887.13,320.66 888.67,317.07 890.21,313.13 891.75,308.81 893.29,304.03 894.83,298.71 896.38,292.76 897.92,286.09 899.46,278.71 901.00,270.89 902.54,263.12 904.08,255.91 905.63,249.48 907.17,243.81 908.71,238.83 910.25,234.44 911.79,230.57 913.33,227.17 914.88,224.18 916.42,221.56 917.96,219.30 919.50,217.37 921.04,215.76 922.58,214.46 924.13,213.44 925.67,212.71 927.21,212.26 928.75,212.08 930.29,212.15 931.83,212.48 933.38,213.06 934.92,213.86 936.46,214.90 938.00,216.14 939.54,217.59 941.08,219.23 942.63,221.04 944.17,223.01 945.71,225.13 947.25,227.39 948.79,229.77 950.33,232.25 951.88,234.82 953.42,237.47 954.96,240.19 956.50,242.95 958.04,245.74 959.58,248.56 961.13,251.39 962.67,254.21 964.21,257.01 965.75,259.79 967.29,262.53 968.83,265.22 970.38,267.86 971.92,270.44 973.46,272.96 975.00,275.40\" stroke-width=\"2pt\" stroke=\"#0af\" /><polyline fill=\"none\" points=\"50.00,285.00 51.54,285.00 53.08,285.00 54.63,284.99 56.17,284.98 57.71,284.95 59.25,284.90 60.79,284.81 62.33,284.68 63.88,284.49 65.42,284.22 66.96,283.85 68.50,283.38 70.04,282.76 71.58,281.98 73.13,281.02 74.67,279.83 76.21,278.39 77.75,276.65 79.29,274.58 80.83,272.13 82.38,269.24 83.92,265.86 85.46,261.92 87.00,257.41 88.54,252.33 90.08,246.79 91.63,241.04 93.17,235.40 94.71,230.20 96.25,225.62 97.79,221.75 99.33,218.62 100.88,216.20 102.42,214.46 103.96,213.37 105.50,212.89 107.04,213.01 108.58,213.69 110.13,214.91 111.67,216.64 113.21,218.86 114.75,221.54 116.29,224.65 117.83,228.17 119.38,232.06 120.92,236.30 122.46,240.86 124.00,245.71 125.54,250.83 127.08,256.21 128.63,261.83 130.17,267.68 131.71,273.76 133.25,280.08 134.79,286.65 136.33,293.50 137.88,300.67 139.42,308.18 140.96,316.11 142.50,324.47 144.04,333.27 145.58,342.45 147.13,351.82 148.67,361.13 150.21,370.13 151.75,378.65 153.29,386.63 154.83,394.08 156.38,401.04 157.92,407.55 159.46,413.65 161.00,419.39 162.54,424.78 164.08,429.87 165.63,434.66 167.17,439.17 168.71,443.41 170.25,447.40 171.79,451.14 173.33,454.63 174.88,457.87 176.42,460.86 177.96,463.61 179.50,466.10 181.04,468.34 182.58,470.31 184.13,472.02 185.67,473.46 187.21,474.62 188.75,475.50 190.29,476.10 191.83,476.41 193.38,476.43 194.92,476.15 196.46,475.58 198.00,474.73 199.54,473.58 201.08,472.14 202.63,470.43 204.17,468.44 205.71,466.19 207.25,463.68 208.79,460.92 210.33,457.92 211.88,454.69 213.42,451.25 214.96,447.61 216.50,443.78 218.04,439.77 219.58,435.61 221.13,431.29 222.67,426.84 224.21,422.26 225.75,417.58 227.29,412.80 228.83,407.92 230.38,402.97 231.92,397.93 233.46,392.82 235.00,387.64 236.54,382.37 238.08,377.02 239.63,371.56 241.17,365.99 242.71,360.27 244.25,354.39 245.79,348.30 247.33,341.96 248.88,335.32 250.42,328.30 251.96,320.81 253.50,312.74 255.04,303.97 256.58,294.33 258.13,283.75 259.67,272.37 261.21,260.69 262.75,249.44 264.29,239.07 265.83,229.68 267.38,221.18 268.92,213.42 270.46,206.28 272.00,199.67 273.54,193.50 275.08,187.71 276.63,182.24 278.17,177.07 279.71,172.16 281.25,167.49 282.79,163.03 284.33,158.77 285.88,154.69 287.42,150.79 288.96,147.05 290.50,143.46 292.04,140.03 293.58,136.74 295.13,133.58 296.67,130.56 298.21,127.66 299.75,124.89 301.29,122.25 302.83,119.72 304.38,117.30 305.92,115.00 307.46,112.81 309.00,110.73 310.54,108.75 312.08,106.88 313.63,105.11 315.17,103.45 316.71,101.89 318.25,100.43 319.79,99.07 321.33,97.82 322.88,96.68 324.42,95.64 325.96,94.72 327.50,93.91 329.04,93.23 330.58,92.67 332.13,92.24 333.67,91.96 335.21,91.81 336.75,91.82 338.29,91.99 339.83,92.33 341.38,92.84 342.92,93.53 344.46,94.41 346.00,95.49 347.54,96.77 349.08,98.25 350.63,99.94 352.17,101.85 353.71,103.97 355.25,106.31 356.79,108.86 358.33,111.64 359.88,114.63 361.42,117.85 362.96,121.29 364.50,124.96 366.04,128.85 367.58,132.98 369.13,137.35 370.67,141.97 372.21,146.85 373.75,152.02 375.29,157.48 376.83,163.27 378.38,169.43 379.92,176.01 381.46,183.05 383.00,190.64 384.54,198.86 386.08,207.79 387.63,217.49 389.17,227.89 390.71,238.73 392.25,249.54 393.79,259.88 395.33,269.56 396.88,278.57 398.42,286.99 399.96,294.92 401.50,302.44 403.04,309.64 404.58,316.57 406.13,323.28 407.67,329.80 409.21,336.14 410.75,342.33 412.29,348.36 413.83,354.23 415.38,359.94 416.92,365.48 418.46,370.81 420.00,375.93 421.54,380.80 423.08,385.40 424.63,389.70 426.17,393.68 427.71,397.30 429.25,400.55 430.79,403.41 432.33,405.85 433.88,407.85 435.42,409.41 436.96,410.52 438.50,411.16 440.04,411.34 441.58,411.04 443.13,410.27 444.67,409.02 446.21,407.30 447.75,405.08 449.29,402.36 450.83,399.12 452.38,395.35 453.92,391.01 455.46,386.08 457.00,380.52 458.54,374.30 460.08,367.46 461.63,360.10 463.17,352.45 464.71,344.82 466.25,337.49 467.79,330.60 469.33,324.21 470.88,318.27 472.42,312.73 473.96,307.53 475.50,302.61 477.04,297.92 478.58,293.42 480.13,289.06 481.67,284.83 483.21,280.69 484.75,276.63 486.29,272.64 487.83,268.70 489.38,264.81 490.92,260.97 492.46,257.18 494.00,253.44 495.54,249.76 497.08,246.16 498.63,242.65 500.17,239.25 501.71,235.98 503.25,232.86 504.79,229.91 506.33,227.17 507.88,224.66 509.42,222.41 510.96,220.44 512.50,218.79 514.04,217.48 515.58,216.55 517.13,216.01 518.67,215.89 520.21,216.22 521.75,217.03 523.29,218.34 524.83,220.19 526.38,222.63 527.92,225.68 529.46,229.43 531.00,233.92 532.54,239.23 534.08,245.43 535.63,252.51 537.17,260.29 538.71,268.35 540.25,276.16 541.79,283.29 543.33,289.61 544.88,295.11 546.42,299.88 547.96,304.01 549.50,307.58 551.04,310.64 552.58,313.28 554.13,315.53 555.67,317.43 557.21,319.03 558.75,320.35 560.29,321.43 561.83,322.29 563.38,322.96 564.92,323.46 566.46,323.80 568.00,324.02 569.54,324.13 571.08,324.15 572.63,324.09 574.17,323.97 575.71,323.79 577.25,323.58 578.79,323.34 580.33,323.07 581.88,322.79 583.42,322.49 584.96,322.18 586.50,321.86 588.04,321.53 589.58,321.18 591.13,320.80 592.67,320.40 594.21,319.96 595.75,319.48 597.29,318.93 598.83,318.30 600.38,317.59 601.92,316.76 603.46,315.81 605.00,314.71 606.54,313.44 608.08,311.97 609.63,310.28 611.17,308.34 612.71,306.10 614.25,303.54 615.79,300.60 617.33,297.23 618.88,293.38 620.42,288.96 621.96,283.89 623.50,278.09 625.04,271.51 626.58,264.20 628.13,256.43 629.67,248.66 631.21,241.37 632.75,234.87 634.29,229.24 635.83,224.45 637.38,220.45 638.92,217.17 640.46,214.55 642.00,212.55 643.54,211.13 645.08,210.25 646.63,209.89 648.17,210.01 649.71,210.60 651.25,211.63 652.79,213.07 654.33,214.90 655.88,217.09 657.42,219.61 658.96,222.43 660.50,225.52 662.04,228.86 663.58,232.41 665.13,236.14 666.67,240.04 668.21,244.08 669.75,248.24 671.29,252.50 672.83,256.85 674.38,261.28 675.92,265.78 677.46,270.37 679.00,275.03 680.54,279.78 682.08,284.64 683.63,289.62 685.17,294.75 686.71,300.07 688.25,305.61 689.79,311.43 691.33,317.59 692.88,324.15 694.42,331.17 695.96,338.68 697.50,346.62 699.04,354.83 700.58,363.00 702.13,370.85 703.67,378.17 705.21,384.86 706.75,390.92 708.29,396.38 709.83,401.28 711.38,405.66 712.92,409.54 714.46,412.95 716.00,415.90 717.54,418.41 719.08,420.49 720.63,422.13 722.17,423.35 723.71,424.13 725.25,424.48 726.79,424.39 728.33,423.88 729.88,422.93 731.42,421.56 732.96,419.77 734.50,417.58 736.04,414.99 737.58,412.01 739.13,408.68 740.67,405.01 742.21,401.03 743.75,396.76 745.29,392.22 746.83,387.45 748.38,382.46 749.92,377.29 751.46,371.96 753.00,366.48 754.54,360.86 756.08,355.13 757.63,349.29 759.17,343.33 760.71,337.25 762.25,331.03 763.79,324.66 765.33,318.11 766.88,311.33 768.42,304.27 769.96,296.87 771.50,289.03 773.04,280.65 774.58,271.63 776.13,261.87 777.67,251.40 779.21,240.49 780.75,229.63 782.29,219.32 783.83,209.82 785.38,201.13 786.92,193.19 788.46,185.89 790.00,179.15 791.54,172.90 793.08,167.07 794.63,161.61 796.17,156.51 797.71,151.72 799.25,147.22 800.79,143.01 802.33,139.06 803.88,135.37 805.42,131.94 806.96,128.75 808.50,125.80 810.04,123.09 811.58,120.62 813.13,118.38 814.67,116.37 816.21,114.59 817.75,113.04 819.29,111.70 820.83,110.57 822.38,109.65 823.92,108.92 825.46,108.39 827.00,108.03 828.54,107.86 830.08,107.84 831.63,107.99 833.17,108.29 834.71,108.72 836.25,109.30 837.79,110.00 839.33,110.82 840.88,111.77 842.42,112.82 843.96,113.99 845.50,115.27 847.04,116.65 848.58,118.13 850.13,119.72 851.67,121.41 853.21,123.21 854.75,125.10 856.29,127.11 857.83,129.22 859.38,131.44 860.92,133.77 862.46,136.22 864.00,138.79 865.54,141.48 867.08,144.30 868.63,147.26 870.17,150.35 871.71,153.59 873.25,156.99 874.79,160.54 876.33,164.27 877.88,168.19 879.42,172.30 880.96,176.63 882.50,181.20 884.04,186.02 885.58,191.13 887.13,196.56 888.67,202.36 890.21,208.59 891.75,215.32 893.29,222.64 894.83,230.67 896.38,239.55 897.92,249.40 899.46,260.22 901.00,271.69 902.54,283.12 904.08,293.88 905.63,303.68 907.17,312.57 908.71,320.66 910.25,328.11 911.79,335.03 913.33,341.52 914.88,347.67 916.42,353.53 917.96,359.14 919.50,364.56 921.04,369.81 922.58,374.92 924.13,379.90 925.67,384.78 927.21,389.57 928.75,394.28 930.29,398.91 931.83,403.47 933.38,407.96 934.92,412.37 936.46,416.70 938.00,420.95 939.54,425.11 941.08,429.17 942.63,433.11 944.17,436.94 945.71,440.64 947.25,444.20 948.79,447.61 950.33,450.85 951.88,453.92 953.42,456.81 954.96,459.50 956.50,461.98 958.04,464.25 959.58,466.29 961.13,468.10 962.67,469.66 964.21,470.97 965.75,472.02 967.29,472.80 968.83,473.31 970.38,473.54 971.92,473.50 973.46,473.17 975.00,472.57\" stroke-width=\"2pt\" stroke=\"#f60\" /><g stroke=\"black\"><line x1=\"50.00\" x2=\"50.00\" y1=\"550.00\" y2=\"560.00\" /><line x1=\"142.50\" x2=\"142.50\" y1=\"550.00\" y2=\"560.00\" /><line x1=\"235.00\" x2=\"235.00\" y1=\"550.00\" y2=\"560.00\" /><line x1=\"327.50\" x2=\"327.50\" y1=\"550.00\" y2=\"560.00\" /><line x1=\"420.00\" x2=\"420.00\" y1=\"550.00\" y2=\"560.00\" /><line x1=\"512.50\" x2=\"512.50\" y1=\"550.00\" y2=\"560.00\" /><line x1=\"605.00\" x2=\"605.00\" y1=\"550.00\" y2=\"560.00\" /><line x1=\"697.50\" x2=\"697.50\" y1=\"550.00\" y2=\"560.00\" /><line x1=\"790.00\" x2=\"790.00\" y1=\"550.00\" y2=\"560.00\" /><line x1=\"882.50\" x2=\"882.50\" y1=\"550.00\" y2=\"560.00\" /><line x1=\"975.00\" x2=\"975.00\" y1=\"550.00\" y2=\"560.00\" /><g fill=\"black\" font-family=\"Arial, sans-serif\" font-size=\"10\" stroke=\"none\" text-anchor=\"middle\"><text x=\"50.00\" y=\"570.00\">0.00</text><text x=\"142.50\" y=\"570.00\">1.00</text><text x=\"235.00\" y=\"570.00\">2.00</text><text x=\"327.50\" y=\"570.00\">3.00</text><text x=\"420.00\" y=\"570.00\">4.00</text><text x=\"512.50\" y=\"570.00\">5.00</text><text x=\"605.00\" y=\"570.00\">6.00</text><text x=\"697.50\" y=\"570.00\">7.00</text><text x=\"790.00\" y=\"570.00\">8.00</text><text x=\"882.50\" y=\"570.00\">9.00</text><text x=\"975.00\" y=\"570.00\">10.00</text></g><line x1=\"50.00\" x2=\"975.00\" y1=\"550.00\" y2=\"550.00\" /></g><g stroke=\"black\"><line x1=\"50.00\" x2=\"40.00\" y1=\"538.06\" y2=\"538.06\" /><line x1=\"50.00\" x2=\"40.00\" y1=\"453.70\" y2=\"453.70\" /><line x1=\"50.00\" x2=\"40.00\" y1=\"369.35\" y2=\"369.35\" /><line x1=\"50.00\" x2=\"40.00\" y1=\"285.00\" y2=\"285.00\" /><line x1=\"50.00\" x2=\"40.00\" y1=\"200.65\" y2=\"200.65\" /><line x1=\"50.00\" x2=\"40.00\" y1=\"116.30\" y2=\"116.30\" /><line x1=\"50.00\" x2=\"40.00\" y1=\"31.94\" y2=\"31.94\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"538.06\" y2=\"538.06\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"521.19\" y2=\"521.19\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"504.32\" y2=\"504.32\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"487.45\" y2=\"487.45\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"470.57\" y2=\"470.57\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"453.70\" y2=\"453.70\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"436.83\" y2=\"436.83\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"419.96\" y2=\"419.96\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"403.09\" y2=\"403.09\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"386.22\" y2=\"386.22\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"369.35\" y2=\"369.35\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"352.48\" y2=\"352.48\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"335.61\" y2=\"335.61\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"318.74\" y2=\"318.74\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"301.87\" y2=\"301.87\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"285.00\" y2=\"285.00\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"268.13\" y2=\"268.13\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"251.26\" y2=\"251.26\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"234.39\" y2=\"234.39\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"217.52\" y2=\"217.52\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"200.65\" y2=\"200.65\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"183.78\" y2=\"183.78\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"166.91\" y2=\"166.91\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"150.04\" y2=\"150.04\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"133.17\" y2=\"133.17\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"116.30\" y2=\"116.30\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"99.43\" y2=\"99.43\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"82.55\" y2=\"82.55\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"65.68\" y2=\"65.68\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"48.81\" y2=\"48.81\" /><line x1=\"50.00\" x2=\"45.00\" y1=\"31.94\" y2=\"31.94\" /><g fill=\"black\" font-family=\"Arial, sans-serif\" font-size=\"10\" stroke=\"none\" text-anchor=\"end\"><text x=\"35.00\" y=\"538.06\">-3.00</text><text x=\"35.00\" y=\"453.70\">-2.00</text><text x=\"35.00\" y=\"369.35\">-1.00</text><text x=\"35.00\" y=\"285.00\">0.00</text><text x=\"35.00\" y=\"200.65\">1.00</text><text x=\"35.00\" y=\"116.30\">2.00</text><text x=\"35.00\" y=\"31.94\">3.00</text></g><line x1=\"50.00\" x2=\"50.00\" y1=\"550.00\" y2=\"20.00\" /></g></g></svg>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(defn export-viz\n",
    "  [spec]\n",
    "  (->> spec\n",
    "       (viz/svg-plot2d-cartesian)\n",
    "       (svg/svg {:width 985 :height 600})\n",
    "       (svg/serialize)))\n",
    "\n",
    "(-> spec\n",
    "    export-viz\n",
    "    display/make-html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Clojure",
   "language": "clojure",
   "name": "clojure"
  },
  "language_info": {
   "file_extension": ".clj",
   "mimetype": "text/x-clojure",
   "name": "clojure",
   "version": "1.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
